<?php
/**
 * This is a demo app.
 *
 * PHP 5
 *
 * MIT License
 * Copyright (c) 2009 Christian Krause
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * @category   library
 * @package    iLivGallery
 * @author     Original Author <ilivgallery@christiankrause.de>
 * @copyright  2009 Christian Krause
 * @license    MIT
 * @link       http://code.google.com/p/ilivgallery/downloads/
 * @since      File available since Release 0.5
 */

require_once 'Core.php';

class iLiv_Gallery extends iLiv_Core {

	protected function resetMirror() {

		if ( $this->scale === 250 )
		{
			$this->setConfigVal('thumbs_mirror', true);
		}
		else
		{
			$this->setConfigVal('thumbs_mirror', false);
		}

	}

	public function simpleImageStack() {

		$this->setHookIn('resetMirror', null, 1);

		foreach ( $this->getImagesOfDir('') as $oImage )
		{
			echo '<a href="demo/thumbs/'.$oImage->scale_down_name[640].'"
					class="group" title="'.$oImage->basename.'">
					<img src="demo/thumbs/'.$oImage->scale_down_name[250].'" alt="" />
				  </a>';
		}

		return true;
	}

}

class iLiv_StaticGallery extends iLiv_Gallery {

	/**
	 * @var iLiv_StaticGallery
	 */
	protected static $instance; 

	/**
	 * @return iLiv_StaticGallery
	 */
	public static function getSingleton() {
		
		if ( self::$instance === null )
		{
			$debugger 	= DebuggerFactory::create('echo');
			$config 	= new iLiv_Config;
			$config->setValue('lightbox_scale', array(640));
			$setup 		= new iLiv_Setup($debugger, $config);

			self::$instance = new self($debugger, $setup);
		}
		
		return self::$instance;
	}

	public function getImageTag($image='', $size=0, $mirror=false) {
	//TODO: BUGFIX, why we have to reset mirror to true, default in config is true
		$this->setConfigVal('thumbs_mirror', $mirror);
		
		if ( $size > 0 && $image !== '' )
		{
			$this->scale = $size;
			$this->setCurFile($image)
				 ->getCurFile()->setScaleDown($size);

			$this->doThumbsHandle();
		}

		return sprintf('<img src="demo/thumbs/%s" alt="" />', $this->curFile->scale_down_name[$size]);
	}

}
